{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from lxml import etree\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-9-2fdd7892a02a>, line 16)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-9-2fdd7892a02a>\"\u001b[1;36m, line \u001b[1;32m16\u001b[0m\n\u001b[1;33m    global title = html.xpath('.//div[@class=\"article\"]/h2/text()')\u001b[0m\n\u001b[1;37m                 ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "url = 'http://angelimg.spbeen.com/ang/10200/1'\n",
    "headers = {\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36'\n",
    "}\n",
    "all_links = [url]\n",
    "img_links = []\n",
    "all_imgs = []\n",
    "title = ''\n",
    "\n",
    "def get_next_links(url):\n",
    "    ## 给定一个链接，返回下一个链接\n",
    "    resp = requests.get(url, headers=headers)\n",
    "    ## 将拿到的响应解析一下，然后就得到了html对象\n",
    "    html = etree.HTML(resp.text)\n",
    "    imgs = html.xpath('.//div[@id=\"content\"]/a/img/@src')\n",
    "    global title\n",
    "    title = html.xpath('.//div[@class=\"article\"]/h2/text()')\n",
    "    all_img = html.xpath('.//img/@src')\n",
    "    all_imgs.extend(all_img)\n",
    "    \n",
    "    img_links.extend(imgs)\n",
    "    next_links = html.xpath('.//div[@id=\"page\"]/a/@href')\n",
    "    for i in next_links:\n",
    "        base_url = 'http://angelimg.spbeen.com'\n",
    "        next_url = base_url + i\n",
    "        if next_url not in all_links:\n",
    "            all_links.append(next_url)\n",
    "\n",
    "for link in all_links:\n",
    "    print('当前请求的链接是：', link)\n",
    "    get_next_links(link)\n",
    "    time.sleep(1)\n",
    "print('当前列表的链接内容为：', [i.split('/')[-1] for i in all_links])\n",
    "print('当前图片链接的列表内容为：',img_links)\n",
    "print('当前全部图片的列表内容为：',all_imgs)\n",
    "print('当前标签的列表内容为：',title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "se = [1, 2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "se.extend([2, 3, 4])\n",
    "print(se)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
